﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Add
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<script type="text/javascript">

    function NewItem() {
        $(document).ready(function () {
            alert("test");
            if (document.getElementById('fileUpload').value == "") {
                alert("No File");
                return;
            }

            var returnJson =
                {
                    "CategoryId": $("#CategoryDDL > option:selected").attr("value"),
                    "Name": document.getElementById('ItemName').value,
                    "Year": document.getElementById('Year').value,
                    "Price": document.getElementById('Price').value,
                    "Description": document.getElementById('Description').value,
                    "PictureLocation": document.getElementById('fileUpload').value
                };
            alert("test");
            $.ajax({
                url: '<%= ResolveUrl("~/UserAdministration/Item/NewItem") %>',
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(returnJson),
                contentType: 'application/json; charset=utf-8',
                success: function (data) {
                    if (data.Check == "0") {
                        alert("fail");
                        return;
                    }
                    if (data.Check == "1") {
                        alert("Success");
                        return;
                    }
                }
            });
        });
    }

</script>

    <h2 style="width: 200px;height:20px">Add New Item</h2>
    <div style="width:200px;"><div id="lblResponse" style="display: none;"></div></div>

     <fieldset>

        <div class="form_settings" style="padding-left:30px; width:512px;">
            <p>
                <span><label for="CategoryId">Category:</label></span>
                <%= Html.DropDownList("CategoryDDL")%>
            </p>
            <p>
                <span><label for="ItemName">Item Name:</label></span>
                <input type="text" id="ItemName"/>
            </p>
            <p>
                <span><label for="Year">Year:</label></span>
                <input type="text" id="Year"/>
            </p>
            <p>
                <span><label for="Price">Price:</label></span>
                <input type="text" id="Price"/>
            </p>
            <p>
                <span>Select file: </span>
                <% using (Html.BeginForm("UploadPicture", "Item", FormMethod.Post, new { enctype = "multipart/form-data" }))
	           { %>
	            <input type="file" id="fileUpload" name="fileUpload" style="width:311px;"/>
                
            </p>
            <p>
                <span><label for="Description">Description:</label></span>
                <textarea id="Description" rows="5"> </textarea>
            </p>

            <p style="padding-left:32px;"><span>&nbsp;</span><input class="submit" type="submit" value="Submit" onclick="NewItem();" /></p>
            <% } %>
        </div>
            
    </fieldset>

</asp:Content>
